package com.aidex.common.core.domain;

import com.aidex.common.core.domain.model.LoginUser;
import com.aidex.common.utils.SecurityUtils;
import com.aidex.common.utils.StringUtils;
import com.aidex.common.utils.spring.SpringUtils;
import com.aidex.common.utils.uuid.IdUtils;
import com.alibaba.fastjson2.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.core.env.Environment;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity基类
 */
@Data
public class BaseEntity implements Serializable {
    /**
     * 删除标记（0：正常；1：删除；）
     */
//    public static final String DEL_FLAG_NORMAL = "0";
//    public static final String DEL_FLAG_DELETE = "1";
    public static final String STATUS_NORMAL = "0";
//    public static final String STATUS_DISABLE = "1";
//    public static final String STATUS_DELETE = "2";
//    public static final String STATUS_FREEZE = "3";
//    public static final String STATUS_AUDIT = "4";
//    public static final String STATUS_AUDIT_BACK = "5";
//    public static final String STATUS_DRAFT = "9";

    //写入日志时记录变更前对象，变更后对象，日志类型（添加，编辑，删除）
//    public static final String LOG_OLD_DATA = "LOG_OLD_DATA";
//    public static final String LOG_NEW_DATA = "LOG_NEW_DATA";
    public static final String LOG_TYPE = "LOG_TYPE";

    @ApiModelProperty("主键ID")
    private String id;

    @ApiModelProperty("搜索值")
    @TableField(exist = false)
    private String searchValue;

    @ApiModelProperty("创建者")
    private String createBy;

    @ApiModelProperty("创建部门")
    private String createDept;

    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty("更新者")
    private String updateBy;

    @ApiModelProperty("更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @ApiModelProperty("更新IP")
    private String updateIp;

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("版本")
    @Version
    private Integer version;

    @ApiModelProperty("删除标记")
    @TableLogic(value = "0", delval = "1")
    protected String delFlag;

    @ApiModelProperty("数据操作类型，行编辑时使用add为添加数据edit为编辑数据标记，delete为删除数据标记")
    @TableField(exist = false)
    protected String handleType;

    @ApiModelProperty("请求参数")
    @TableField(exist = false)
    private Map<String, Object> params;

    public Map<String, Object> getParams() {
        if (params == null) {
            params = new HashMap<>(16);
        }
        return params;
    }
}
